﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Configuration;
using Microsoft.ReportingServices;
using Microsoft.Reporting.WinForms;

namespace Autocentro.UI.Reportes
{
    public partial class FrmRepProforma : Form
    {
        public string placaTxt;
        public int IdProforma;
        public bool igv;

        public FrmRepProforma()
        {
            InitializeComponent();
        }

        private void FrmRepProforma_Load(object sender, EventArgs e)
        {
            if (igv)
            {
                reportViewer1.ShowPageNavigationControls = false;
                reportViewer1.ShowCredentialPrompts = false;

                var user = ConfigurationManager.AppSettings.Get("userReport");
                var pws = ConfigurationManager.AppSettings.Get("pwsReport");
                reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = new NetworkCredential(user, pws);

                var ipServer = ConfigurationManager.AppSettings.Get("ipServer");
                var path = ConfigurationManager.AppSettings.Get("pathM");
                reportViewer1.ProcessingMode = ProcessingMode.Remote;
                reportViewer1.ServerReport.ReportPath = path;
                reportViewer1.ServerReport.ReportServerUrl = new Uri(ipServer, System.UriKind.Absolute);

                ReportParameter[] parameters = new ReportParameter[1];
                parameters[0] = new ReportParameter("IdProforma", IdProforma.ToString());

                reportViewer1.ServerReport.SetParameters(parameters);
                this.reportViewer1.RefreshReport();    
            }
            else
            {
                reportViewer1.ShowPageNavigationControls = false;
                reportViewer1.ShowCredentialPrompts = false;

                var user = ConfigurationManager.AppSettings.Get("userReport");
                var pws = ConfigurationManager.AppSettings.Get("pwsReport");
                reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = new NetworkCredential(user, pws);

                var ipServer = ConfigurationManager.AppSettings.Get("ipServer");
                var path = ConfigurationManager.AppSettings.Get("pathN");
                reportViewer1.ProcessingMode = ProcessingMode.Remote;
                reportViewer1.ServerReport.ReportPath = path;
                reportViewer1.ServerReport.ReportServerUrl = new Uri(ipServer, System.UriKind.Absolute);

                ReportParameter[] parameters = new ReportParameter[1];
                parameters[0] = new ReportParameter("IdProforma", IdProforma.ToString());

                reportViewer1.ServerReport.SetParameters(parameters);
                this.reportViewer1.RefreshReport();
            }
            
            
        }

        public int ObtenerId(int id)
        {
            IdProforma = id;
            return IdProforma;
        }

    }
}
